<template>
  <div
    class="wrap-item"
    :style="{
      '--scroll-width': '80px',
    }"
  >
    <div class="wrap-btn-group">
      <span class="wrap-btn wrap-go-back" @click="go">返回</span>
    </div>
    <div class="wrap-other-roll">
      <!-- 基础信息 -->
      <div class="card">
        <div class="title">基础信息</div>
        <el-descriptions direction="vertical" :column="2" border>
          <el-descriptions-item>
            <template slot="label">标题</template>
            {{ info.title }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">类型</template>
            <span v-if="info.msgType == 0">公告</span>
            <span v-if="info.msgType == 1">消息</span>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">是否置顶</template>
            <span v-if="info.topFlag == 0">是</span>
            <span v-if="info.topFlag == 1">否</span>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">级别</template>
            <span v-if="info.msgLevel == 0">普通</span>
            <span v-if="info.msgLevel == 1">重要</span>
            <span v-if="info.msgLevel == 2">非常重要</span>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">浏览量</template>
            {{ info.readNum }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">状态</template>
            <span v-if="info.msgStatus == 0">保存</span>
            <span v-if="info.msgStatus == 1">已发布</span>
            <span v-if="info.msgStatus == 2">已关闭</span>
          </el-descriptions-item>
          <el-descriptions-item :span="2">
            <template slot="label">内容</template>
            <div class="wrap-html" v-html="info.content"></div>
          </el-descriptions-item>
          <el-descriptions-item :span="2">
            <template slot="label">附件</template>
            <el-table :data="files" v-if="files.length > 0">
              <el-table-column prop="name" label="名称">
                <template slot-scope="scope">
                  <el-tooltip
                    popper-class="ellipsis-tip"
                    :content="scope.row.name"
                    placement="top-start"
                  >
                    <span class="ellipsis">{{ scope.row.name }}</span>
                  </el-tooltip>
                </template>
              </el-table-column>
              <el-table-column prop="size" label="大小"></el-table-column>
              <el-table-column
                prop="content"
                label="操作"
                width="50px"
                align="center"
              >
                <template slot-scope="scope">
                  <el-link
                    type="primary"
                    :underline="false"
                    @click="downloadFile(scope.row)"
                    >下载</el-link
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">发布人</template>
            {{ info.addName }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">发布时间</template>
            {{ info.addTime }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <!-- 审批信息 -->
      <div class="card">
        <div class="title">审批信息</div>
        <el-table
          :data="approves"
          :header-cell-style="{ background: '#F6F7F9' }"
        >
          <el-table-column prop="title" label="节点名称"> </el-table-column>
          <el-table-column prop="taskUserName" label="处理人">
          </el-table-column>
          <el-table-column label="处理结果">
            <template slot-scope="scope">
              <span v-if="scope.row.status == 0">正在执行中</span>
              <span v-if="scope.row.status == 1">通过</span>
              <span v-if="scope.row.status == 2">驳回</span>
            </template>
          </el-table-column>
          <el-table-column prop="auditNote" label="处理意见">
            <template slot-scope="scope">
              <el-tooltip
                popper-class="ellipsis-tip"
                :content="scope.row.auditNote"
                placement="top-start"
              >
                <span class="ellipsis">{{ scope.row.auditNote }}</span>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column prop="updateTime" label="处理时间">
          </el-table-column>
          <el-table-column label="附件" width="50px" align="center">
            <template slot-scope="scope">
              <el-link
                type="primary"
                :underline="false"
                @click="view(scope.row)"
                >查看</el-link
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <file-preview
        :visible="isLook"
        :data="lookData"
        @close="isLook = false"
      />
    </div>
  </div>
</template>

<script>
import filePreview from '@c/filePreview.vue'
export default {
  components: { filePreview },
  data() {
    return {
      info: {},
      approves: [],
      lookData: [],
      isLook: false,
      files: [],
    }
  },
  created() {
    if (this.$route.query.id) {
      this.itemList()
    }
  },
  methods: {
    go() {
      //返回
      this.$store.dispatch('tags/delVisitedRoute', {
        path: this.$route.path,
      })
      this.$router.push('/portalCenter/notice')
    },
    itemList() {
      // 获取列表
      this.$axios
        .get(`/admin/portal/msg/find?id=${this.$route.query.id}`)
        .then((data) => {
          this.info = {}
          this.approves = []
          if (data.code == 200) {
            this.info = data.data.info || {}
            this.files=JSON.parse(data.data.info.files)
            this.approves = data.data.approves || []
          } else {
            this.$message.error(data.msg)
          }
        })
    },
    view(item) {
      //查看
      this.lookData = this.fileArr(item.auditFile)
      this.isLook = true
    },
    fileArr(fileStr) {
      if (Object.prototype.toString.call(fileStr).slice(8, -1) === 'Array') {
        return fileStr
      } else {
        let arrtry = []
        try {
          arrtry = fileStr ? JSON.parse(fileStr) : []
          return arrtry
        } catch (error) {
          arrtry = []
          return arrtry
        }
      }
    },
    downloadFile(item) {
      //下载附件
      const a = document.createElement('a')
      a.download = item.name
      a.href = item.fileDomain + item.url
      a.click()
    },
  },
}
</script>
<style lang="scss" scoped>
.card {
  padding-bottom: 20px;
  .title {
    color: #45ab49;
    border-bottom: 1px solid #45ab49;
    padding: 10px 0;
    margin-bottom: 15px;
  }
}
</style>
